{include file="common/header" /}
<link rel="stylesheet" href="__LAYUIMINI__/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<style type="text/css">
    
    .submit-button{
        display: flex;
        position: fixed;
        bottom: 0;
        width: 100%;
        background: #fff;
        border-top: 1px solid #e6e6e6;
        padding: 12px 0;
        margin: 0;
        z-index: 1000;
    }

</style>
<body style="background-color: #ffffff; margin-left: 0;margin-bottom: 100px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>{$title}</legend>
</fieldset>
<div class="">
    <form id="form" class="layui-form layuimini-form" action="{:url()}"> 
        
        {if input("param.catid") /}
        <div class="layui-form-item">
            <label class="layui-form-label required">分类</label>
            <div class="layui-input-block" style="width: 500px;">
                <select name="catid">
                  <!-- <option value="">顶级</option> -->
                  {volist name="$treeList" id="vo"}
                  <option value="{$vo.id}" {if $vo.id == input("param.catid") /} selected="" {/if}  {if $vo.module != $module /} disabled {/if} >{$vo.catname | raw}</option>
                  {/volist}
                </select>
            </div>
        </div>
        {/if}


        {include file="common/form"}


        <div class="layui-form-item submit-button" >
            <div class="layui-input-block">
                
                {if condition="input('param.id')"}
                <input type="hidden" name="id" value="{:input('param.id')}">
                {/if}
                <!-- <input type="hidden" name="catid" value="{:input('param.catid')}"> -->
                <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="goBack()" >返回</button>
            </div>
        </div>
    </form>
</div>

<script>
    {if condition="isset($table_res)"}
    var formData = {:json_encode($table_res)};
    {else /}
    var formData = '';
    {/if}
    
</script>
<script src="__STATIC__/admin/js/formData.js"></script>

<script>

    layui.use(['form','upload','laydate','layedit'], function () {
        var form = layui.form,
        layedit = layui.layedit,
            layer = layui.layer,
            $ = layui.$;

        

        window.imgdelete = function(dom){
            $(dom).parent().remove();
        }

        window.goBack = function(dom){
            window.location.href = "{:url(CONTROLLER_NAME.'/list')}?cate_id={:input('param.catid')}";
        }
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.load(1, {
                shade: [0.3,'#000'] //0.1透明度的白色背景
            });
            var data = data.field;
            let action = $("#form").attr("action");
            $.ajax({
                url:action,
                data:data,
                type:'post',
                dataType:'json',
                success:function(res){
                    // layer.close(index);
                    // console.log(res)
                    // return false
                    if(res.errcode != 1){
                        layer.msg(res.message,{icon: 2,time: 2000},function(){
                            layer.close(index);
                        })
                    }else{
                        layer.msg(res.message,{icon: 1,time: 1000},function () {
                            window.location.href = "{:url(CONTROLLER_NAME.'/list')}?cate_id={:input('param.catid')}";
                        })
                    }
                    layer.close(index);
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络失败，请刷新页面后重试!',{icon: 2,time: 2000})
                }
            });

            return false;
        });

    });
</script>
</body>
</html>